#include <stdio.h>
struct textBook{
    char name[20],tel[20];
    int year,mon,day;
}text[205];
int nextN[205],cnt,head=1;
int main(){
    int n,m;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s %s %d %d %d",text[i].name,text[i].tel,&text[i].year,&text[i].mon,&text[i].day);
        nextN[i]=i+1;
    }
    nextN[n]=0;
    cnt=n;
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        int t;
        scanf("%d",&t);
        if(t==1){
            int nexti=head;
            scanf("%d",&t);
            cnt++;
            scanf("%s %s %d %d %d",text[cnt].name,text[cnt].tel,&text[cnt].year,&text[cnt].mon,&text[cnt].day);
            if(t){
                t--;
                while(t>0&&nextN[nexti]){
                    t--;
                    nexti=nextN[nexti];
                }
           
                int tmp=nextN[nexti];
                nextN[nexti]=cnt;
                nextN[cnt]=tmp;
            }else{
                int tmp=head;
                nextN[cnt]=tmp;
                head=cnt;
            }
        }else{
            scanf("%d",&t);
            if(t){
                int nexti=head;
                t--;
                while(t>0&&nextN[nexti]){
                    t--;
                    nexti=nextN[nexti];
                }
                nextN[nexti]=nextN[nextN[nexti]];
            }else{
                head=nextN[head];
            }
        }
    }
    int i=0;
    while(head){
        printf("%d %s %s %d %d %d\n",i,text[head].name,text[head].tel,text[head].year,text[head].mon,text[head].day);
        head=nextN[head];
        i++;
    }
    return 0;
}